package org.example.session;

import cn.hutool.core.lang.Pair;
import com.alibaba.ttl.TransmittableThreadLocal;
import org.example.model.dto.FullUserDto;

/**
 * @author weigang
 * @create 2022-11-08 14:49
 */
public class UserContext {
    private UserContext() {
    }

    private static ThreadLocal<Pair<String, FullUserDto>> userHolder = new TransmittableThreadLocal<>();

    public static void putUser(Pair<String, FullUserDto> fullUser) {
        userHolder.set(fullUser);
    }

    public static void clear() {
        userHolder.remove();
    }

    public static FullUserDto getUser() {
        return userHolder.get().getValue();
    }

    public static String getToken() {
        return userHolder.get().getKey();
    }

    public static Pair<String, FullUserDto> get() {
        return userHolder.get();
    }
}
